﻿@{
    ViewBag.Title = "课程管理";
    Layout = "~/Views/Shared/_GridCommonLayout.cshtml";
}

<!--begin grid code-->
<section id="widget-grid" class="">
    <div class="row">
        <!--Operation-->
        <div class="heading-buttons">

            <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
                <h1 class="page-title txt-color-blueDark"><i class="fa fa-file  "></i>
                    课程管理
			
                </h1>
            </div>
            <div class="buttons pull-right">

                <button type="button" class="btn btn-success btn-labeled "
                    data-bind="click: $root.showAddBefore">
                    <span class="btn-label"><i class="glyphicon glyphicon-plus"></i>
                    </span>添加记录</button>

                <button type="button" class="btn btn-primary btn-labeled "
                    data-bind="click: $root.onDataDeleting">
                    <span class="btn-label"><i class="glyphicon glyphicon-remove"></i>
                    </span>批量删除</button>


            </div>
            <div style="clear: both;">
            </div>
        </div>
        <!--/Operation-->




        <!--Search-->
        <div class="filter-bar">
            <form id="formSearch">
                <div class="lbl glyphicons search" style="cursor: pointer;" data-bind="click: $root.search">
                    <i></i>筛选
                </div>
                <div>
                    <label>课程编码：</label><div class='input-append'>
                        <input id='txtbSrSCourseCode' name='txtbSrSCourseCode' type='text' placeholder='课程编码' class='input-mini' style='width: 120px;' />
                    </div>
                </div>
                <div>
                    <label>课程名称：</label><div class='input-append'>
                        <input id='txtbSrSCourseName' name='txtbSrSCourseName' type='text' placeholder='课程名称' class='input-mini' style='width: 120px;' />
                    </div>
                </div>
                <div>
                    <label>所属学院/部门：</label><div class='input-append'>
                        @Html.DropDownList("txtbSrSPartName", new SelectList(ViewBag.collegeList, "SCollegeName", "SCollegeName"), "--请选择--", new { @style = "top: 3px;width: 120px;border:1px solid #cccccc" })
                    </div>
                </div>





                <div class="clearfix">
                </div>
            </form>
        </div>
        <!--/search-->



        <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12 sortable-grid ui-sortable">
            <div id="wid-id-0" class="jarviswidget jarviswidget-color-darken jarviswidget-sortable" data-widget-editbutton="false">
                <header>
                    <span class="widget-icon"><i class="fa fa-table"></i></span>
                    <h2>所有课程</h2>
                </header>
                <div style="margin-top: 35px;">
                    <div class="jarviswidget-editbox"></div>
                    <div class="widget-body no-padding">
                        <div role="grid" id="providerGrid" class="dataTables_wrapper form-inline">
                            <div class="table-responsive">

                                <div class="dt-wrapper" style="overflow-y: auto;">
                                    <table class="table table-striped table-bordered table-hover checkboxs">
                                        <!--table head-->
                                        <thead>
                                            <tr>
                                                <th style="width: 1%">
                                                    <input type="checkbox" value="0" />
                                                </th>
                                                <!-- ko foreach: headers -->
                                                <th class="center ">
                                                    <a href="#" data-bind="text: displayText@*, click: $root.sort*@" style="color: black"></a>
                                                    <i class="icon-circle-arrow-up" data-bind="    visible: value == $root.orderBy() && $root.isAsc()"></i>
                                                    <i class="icon-circle-arrow-down" data-bind="    visible: value == $root.orderBy() && !$root.isAsc()"></i>
                                                </th>
                                                <!-- /ko -->
                                                <th class="center" style="width: 60px">操作
                                                </th>
                                            </tr>
                                        </thead>
                                        <!--/table head-->
                                        <!--table body(Provider list)-->
                                        <tbody data-bind="foreach: recordSet">
                                            <tr class="selectable" onclick="">
                                                <td class="center">
                                                    <input type="checkbox" name="userSelector" data-bind="value: Id" />
                                                    <input type="hidden" data-bind="value: Id, attr: { id: Id }" />
                                                </td>

                                                <td class='center'><strong data-bind='text: Id'></strong></td>
                                                <td class='center'><strong data-bind='text: SCourseCode'></strong></td>
                                                <td class='center'><strong data-bind='text: SCourseName'></strong></td>
                                                <td class='center'><strong data-bind='text: SPartName'></strong></td>
                                                <td style="text-align: center;width: 115px;"><button class="btn btn-link" style="height: 20px;font-size:14px" data-bind="click:$root.catalog">编辑教学大纲</button></td>

                                                <td class="center">
                                                    <a href="#" class="btn-action glyphicons pencil btn-success" data-bind="click: $root.showUpdateModal">
                                                        <i></i></a>
                                                </td>
                                                
                                            </tr>
                                        </tbody>
                                        <!--/table body( Provider list)-->

                                    </table>

                                </div>



                                <!-- 分页 -->
                                <ul class="pagination pagination-alt">
                                    <li>
                                        <a data-bind="click: firstPage"><i class="fa fa-fast-backward "></i></a>
                                    </li>
                                    <li>
                                        <a data-bind="click: prevPage"><i class="fa  fa-backward  "></i></a>
                                    </li>
                                    <li>
                                        <a>
                                            <input id="toPage" type="text" data-bind="value: pageIndex, event: { change: $root.changePageIndex }" style="width: 25px;" />
                                            /共<span data-bind="html: totalPages"></span>页 
                                        </a>
                                    </li>
                                    <li>
                                        <a data-bind="click: nextPage"><i class="fa fa-forward "></i></a>
                                    </li>
                                    <li>
                                        <a data-bind="click: lastPage"><i class="fa fa-fast-forward "></i></a>
                                    </li>
                                </ul>

                                <div class="dt-top-row total  ">
                                    当前记录共：<span data-bind="html: totalCount"></span>条
                                </div>
                                <!--end 分页-->
                            </div>

                            <!-- /分页 -->

                        </div>

                        <!-- /分页 -->
                    </div>
                </div>

            </div>

        </article>

    </div>
    <!--end row-->
</section>


<!--DeanCourse详细对话框-->
<div id="DeanCourseMessageModal" class="modal fade" id="ProviderMessageModal" tabindex="-1" role="dialog"
    aria-labelledby="DeanCourseMessageModalLabel" aria-hidden="true">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                ×</button>
            <h3>课程详细信息
            </h3>
        </div>
        <div class="modal-body">

            <input type='hidden' id='txtbID' name='txtbID' />
            <form class="smart-form" id="formDeanCourse" data-bind="with: NodeValue" >
                <fieldset>
                    <div class="row">
                        <section class="col col-6">
                            <label class="label">课程编号:</label>
                            <label class="input">
                                <input type='text' id='txtbSCourseCode' name='txtbSCourseCode' placeholder='课程编码' class='span10' data-bind='value:SCourseCode' />
                            </label>
                        </section>
                        <section class="col col-6">
                            <label class="label">课程名称:</label>
                            <label class="input">
                                <input type='text' id='txtbSCourseName' name='txtbSCourseName' placeholder='课程名称' class='span10' data-bind='value:SCourseName' />
                            </label>
                        </section>
                    </div>
                    <div class="row">
                        <section class="col col-6">
                            <label class="label">所属学院:</label>
                            <label class="select">
                                @Html.DropDownList("txtbIPartId", new SelectList(ViewBag.collegeList, "Id", "SCollegeName"), "--请选择--", new { @data_bind = "value:IPartId" })
                            </label>
                        </section>
                        <section class="col col-6">
                            <label class="label">课程类型:</label>
                            <label class="select">
                                @{
                                    List<SelectListItem> TypelList = new List<SelectListItem>();
                                    TypelList.Add(new SelectListItem { Text = "理论", Value = "1" });
                                    TypelList.Add(new SelectListItem { Text = "实验", Value = "2" });
                                    TypelList.Add(new SelectListItem { Text = "设计", Value = "3" });                               
                                }
                                @Html.DropDownList("txtbIType", TypelList as IEnumerable<SelectListItem>, "--请选择--", new { @data_bind = "value:IType" })
                            </label>
                        </section>
                    </div>
                    <div class="row">
                        <section class="col col-6">
                            <label class="label">课程等级:</label>
                            <label class="select">
                                @{
                                    List<SelectListItem> LevelList = new List<SelectListItem>();
                                    LevelList.Add(new SelectListItem { Text = "一般", Value = "1" });
                                    LevelList.Add(new SelectListItem { Text = "校级精品", Value = "2" });
                                    LevelList.Add(new SelectListItem { Text = "市级精品", Value = "3" });
                                    LevelList.Add(new SelectListItem { Text = "国家级", Value = "4" });                                
                                }
                                @Html.DropDownList("txtbILevel", LevelList as IEnumerable<SelectListItem>, "--请选择--", new { @data_bind = "value:ILevel" })
                            </label>
                        </section>
                        <section class="col col-6">
                            <label class="label">课程难度:</label>
                            <label class="input">
                                <input type='text' id='txtbIHardLevel' name='txtbIHardLevel' placeholder='10分表示最高,0分表示初级' class='span10' data-bind='value:IHardLevel' />
                            </label>
                        </section>
                    </div>
                    <div class="row">
                        <section class="col col-6">
                            <label class="label">关键字:</label>
                            <label class="input">
                                <input type='text' id='txtbSKeyWord' name='txtbSKeyWord' placeholder='100以内字' class='span10' data-bind='value:SKeyWord' />
                            </label>
                        </section>
                        <section class="col col-6">
                            <label class="label">总课时:</label>
                            <label class="input">
                                <input type='text' id='txtbIHours' name='txtbIHours' placeholder='总课时，整数小时为单位' class='span10' data-bind='value:IHours' />
                            </label>
                        </section>
                    </div>
                    <div class="row">

                        <section class="col col-6">
                            <label class="label">授课语言:</label>
                            <label class="input">
                                <input type='text' id='txtbSLanguage' name='txtbSLanguage' placeholder='中文默认为空' class='span10' data-bind='value:SLanguage' />
                            </label>  
                        </section>                  
                    </div>
                    <section>
                        <label class="label">课程简介:</label>
                        <label class="input">
                            <textarea id='txtbSIntro' name='txtbSIntro' placeholder='' class='span10' data-bind='value:SIntro' style="width: 529px; height: 81px;"></textarea>
                        </label>
                    </section>
                    @*<input type="hidden" id='txtbSPartName' name='txtbSPartName' data-bind='value:txtbSPartName' />*@
                </fieldset>
            </form>
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">
                取消</button>
            <button id="btnSaveOrUpdateModel" class="btn btn-primary" aria-hidden="true" data-bind=" click: onDataAddingOrUpdate">
                确定</button>
        </div>
    </div>
    <!--end div content-->
</div>
<!--/详细DeanCourse对话框-->

<script src="~/Js/plugin/summernote/summernote.js"></script>
<script type="text/javascript">

    var gdViewModel;

    $(function () {



        $._messengerDefaults = {
            extraClasses: 'messenger-fixed messenger-theme-future messenger-on-bottom messenger-on-right'
        }; //默认提示位置;


        var options = {

            dialogId: "DeanCourseMessageModal", //添加对话框

            pageSize: 20, //分页大小
            hidId: $("#txtbID"),
            SaveUpdateBtn: $("#btnSaveOrUpdateModel"),
            frmElement: $("#formDeanCourse"),

            //节点数据
            NodeValue: ko.observable({

                Id: 0,
                SCourseCode: '',
                SCourseName: '',
                IPartId: 0,
                SPartName: '',
                ILevel: '',
                IHardLevel: '',
                SKeyWord: '',
                IHours: '',
                IType: '',
                SLanguage: '',
                SIntro: ''
            }),


            //用户列表Grid头部列名称
            headers: [


 { displayText: 'ID', value: 'Id', width: 'auto' },
 { displayText: '课程编码', value: 'SCourseCode', width: 'auto' },
 { displayText: '课程名称', value: 'SCourseName', width: 'auto' },
 { displayText: '开课学院的名称', value: 'SPartName', width: 'auto' },
 { displayText: '编辑教学大纲', value: 'Id' }

            ],

            //默认的排序方式
            defaultOrderBy: "Id",
            //用户查询URL
            dataQueryUrlAccessor: function () {
                return "/api/DeanCourse/GetByPage";
            },

            //添加用户URL
            dataAddUrlAccessor: function () { return "/api/DeanCourse/Post"; },
            dataUpdateAccessor: function (key) {
                options.NodeValue().SPartName = $("#txtbIPartId").find("option:selected").text();
                return "/api/DeanCourse/Put/" + key;
            },
            dataNodeSelect: function (id) {
                return "/api/DeanCourse/get/" + id;
            },

            dataDeleteAccessor: function (data) {
                var userIDs = "";
                var check = $("input:checked");  //得到所有被选中的checkbox
                check.each(function (i) {        //循环拼装被选中项的值
                    userIDs = userIDs + ',' + $(this).val();
                });
                //清除多余的分割号
                userIDs = dropRsplit(userIDs, ",");
                if (userIDs != "") {
                    return appendQueryString("/api/DeanCourse/DeleteIds", { ids: userIDs });
                } else
                    return "";

            }
			, initEd: function () {
			    //gird初始化的后置事件 信息

			}
            , AddBefore: function () {
                options.NodeValue().SPartName = $("#txtbIPartId").find("option:selected").text();
                return true;
            }
             , showDlgBefore: function () {
             }

            , changeEnd: function () {

            }
            , showDetailEnd: function () {
            }


        };

        gdViewModel = new gridViewModel(options);
        gdViewModel.catalog = function (data) {
            window.location = "/SysManger/TeachingOutline?id=" + data.Id;
        }

        gdViewModel.init();
        ko.applyBindings(gdViewModel);


        options.frmElement.validate({
            rules: {
                txtbId: { required: true, digits: true },
                txtbSCourseCode: { maxlength: 50, required: true },
                txtbSCourseName: { maxlength: 50 },
                txtbIPartId: { digits: true },
                txtbSPartName: { maxlength: 50 },
                txtbIHardLevel: { digits: true },
                txtbSKeyWord: { maxlength: 100 },
                txtbIHours: { digits: true },

            },
            messages: {
                txtbId: { required: '必填项', digits: '必须是整数' },
                txtbSCourseCode: { maxlength: '最大长度为10', required: '必填' },
                txtbSCourseName: { maxlength: '最大长度为25' },
                txtbIPartId: { digits: '必须是整数' },
                txtbSPartName: { maxlength: '最大长度为25' },
                txtbIHardLevel: { digits: '请填入整数' },
                txtbSKeyWord: { maxlength: '一百字以内' },
                txtbIHours: { digits: '请输入整数，小时为单位' },

            }
        });

        $("#txtbSCourseCode").blur(function () {
            $.getJSON("/AddVaildate/AddDeanCourse?SCourseCode=" + $("#txtbSCourseCode").val(), function (data) {
                if (data != "") {
                    alert("课程编号已存在，请重新输入")
                    $("#txtbSCourseCode").val("");
                }
            })
        })


    });

</script>






<!--/end grid code-->
